﻿using DailyApp.WPF.HttpClients;
using DailyApp.WPF.ViewModels;
using DailyApp.WPF.Views;
using DryIoc;
using Prism.DryIoc;
using Prism.Ioc;
using Prism.Services.Dialogs;
using System.Configuration;
using System.Data;
using System.Windows;

namespace DailyApp.WPF
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterDialog<LoginUC,LoginUCViewModel>();

            containerRegistry.GetContainer().Register<HttpRestClient>();
            //主页导航页注册
            containerRegistry.RegisterForNavigation<HomeUC, HomeUCViewModel>();
            containerRegistry.RegisterForNavigation<WaitUC, WaitUCViewModel>();
            containerRegistry.RegisterForNavigation<MemoUC, MemoUCViewModel>();
            containerRegistry.RegisterForNavigation<SettingsUC, SettingsViewModel>();

            //设置导航页注册
            containerRegistry.RegisterForNavigation<PersionalUC, PersionalUCViewModel>();
            containerRegistry.RegisterForNavigation<SysSetUC, SysSetUCViewModel>();
            containerRegistry.RegisterForNavigation<AboutUsUC, AboutUsUCViewModel>();
        }

        protected override void OnInitialized()
        {
            var dialog = Container.Resolve<IDialogService>();
            dialog.ShowDialog("LoginUC", t =>
            {
            if (t.Result != ButtonResult.OK)
            {
                Environment.Exit(0); return;
            }
            if (t.Parameters.ContainsKey("UserName"))
            {
                var para = t.Parameters.GetValue<string>("UserName");
                (Current.MainWindow.DataContext as MainWindowViewModel).Init(para);
                }
            });
            base.OnInitialized();
        }

    }

}
